import yaml


# 读取
def read_yaml(yaml_path):
    with open(yaml_path, encoding="utf-8") as f:
        value = yaml.safe_load(f)
        return value


# 读取yaml中指定键的值
def read_yaml_key(yaml_path, key):
    with open(yaml_path, encoding="utf-8") as f:
        value = yaml.safe_load(f)
        return value[key]


# 覆盖写入
def write_yaml(yaml_path, data):
    with open(yaml_path, encoding="utf-8", mode="w") as f:
        yaml.safe_dump(data, stream=f, allow_unicode=True)


# 追加写入
def append_yaml(yaml_path, data):
    with open(yaml_path, encoding="utf-8", mode="a+") as f:
        yaml.safe_dump(data, stream=f, allow_unicode=True)


# 清空
def clear_yaml(yaml_path):
    with open(yaml_path, encoding="utf-8", mode="w") as f:
        f.truncate()
